package com.leiduoduo.oms.service;

import com.leiduoduo.oms.dao.DishDao;
import com.leiduoduo.oms.pojo.Dish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class DishServiceImpl implements DishService {
    @Autowired
    DishDao dishDao;

    @Override
    public boolean addDish(Dish dish) {
        dish.setCreated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))
                .setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return dishDao.addDish(dish);
    }

    @Override
    public boolean delDish(Dish dish) {
        dish.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return dishDao.delDish(dish);
    }

    @Override
    public boolean upDish(Dish dish) {
        dish.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return dishDao.upDish(dish);
    }

    @Override
    public Dish getDishById(int id) {
        return dishDao.getDishById(id);
    }

    @Override
    public List<Dish> getDishList() {
        return dishDao.getDishList();
    }

    @Override
    public List<Dish> getDishListByRestId(int restaurant_id) {
        return dishDao.getDishListByRestId(restaurant_id);
    }
    @Override
    public Double getMoneyByDish(List<Integer> dishIds){
        return dishDao.getMoneyByDish(dishIds);
    }
}
